<?php

use yii\db\Migration;

/**
 * Class m180731_083022_create_comments_matching
 */
class m180731_083022_create_comments_matching extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%comments_matching}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(255)->defaultValue(0)->comment('评价配比名称'),
                'number' => $this->integer(11)->defaultValue(0)->comment('需要的条目数量'),
                'calculation' => $this->string(255)->defaultValue(0)->comment('计算公式'),
                'user_id' => $this->integer(11)->defaultValue(0)->comment('添加管理员id'),
                'status' => $this->smallInteger(2)->defaultValue(0)->comment('状态 0关闭 1 正常 '),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('创建时间'),
                'updated_at' => $this->integer(11)->defaultValue(0)->comment('更新时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%comments_matching}}');
        }
    }
}
